home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
-
- # sda dev:=/dev/sda4;addopts:=utimeout=5
-
- $option = shift @ARGV;
- $device = shift @ARGV;
- $mntline= shift @ARGV;
-
- if (!$option || !$device) {
- print STDERR "$0\t--insert <device> [<mntline>]\n";
- print STDERR "\t--remove <device>\n";
- exit 0;
- }
-
- if (!$mntline || ($mntline eq "")) {
- $mntline = "dev:=/dev/$device;addopts:=utimeout=5";
- }
-
- %devs = ();
- $done = 0;
-
- open(LOCALDEV,"/etc/am.d/localdev")||die "cannot open localdev:$!\n";
- @localdev = <LOCALDEV>;
- chomp(@localdev);
- foreach (@localdev) {
- chomp;
- next if (/^#/);
- next if (/^\s*$/);
-
- next unless (/^([a-zA-Z0-9*]*)\s*(.*)$/);
- if ($1 eq $device) {
- if ($option eq '--remove') {
- $_ = "";
- } else {
- if ($option eq '--insert') {
- $_ = "$device\t\t$mntline";
- }
- }
- $done = 1;
- last;
- }
- }
- close(LOCALDEV);
-
- if (!$done) {
- if ($option eq '--insert') {
- push @localdev,"$device\t\t$mntline";
- }
- if ($option eq '--remove') {
- exit 0; # no need to rewrite localdev
- }
- }
-
- open(LOCALDEV,">/etc/am.d/localdev")||die "could not open localdev for writing:$!\n";
- print LOCALDEV join("\n",@localdev) . "\n";
-
- close(LOCALDEV);
-
- mkdir("/mnt/$device",755);
- system("/usr/bin/amq -f");
-